﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Lesson6_code : MonoBehaviour
{
    public Transform target;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        Debug.DrawRay(this.transform.position, this.transform.forward, Color.red);
        Debug.DrawRay(this.transform.position, target.position - this.transform.position, Color.red);

        float distance = Vector3.Distance(this.transform.position, target.transform.position);
        if (distance <= 5)
        {
            float angle = Vector3.Angle(this.transform.forward, target.position - this.transform.position);
            if (angle <= 22.5)
            {
                Debug.LogFormat("发现入侵者 angle:{0} distance:{1}", angle, distance);
            }
        }
    }
}
